{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-input-inline layui-form">
                            <select name="order_status"  class="layui-input">
                                <option value="">全部订单</option>
                                <option value="1">待审核</option>
                                <option value="2">已同意(待寄回)</option>
                                <option value="3">已拒绝</option>
                                <option value="4">返厂中(用户已寄回)</option>
                                <option value="5">检修中</option>
                                <option value="6">已回寄给用户</option>
                                <option value="7">已完成</option>
                                <option value="8">已取消</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <select name="order_jiance_status"  class="layui-input">
                                <option value="">不限检测状态</option>
                                <option value="1">待检测</option>
                                <option value="2">已同意</option>
                                <option value="3">已拒绝</option>
                            </select>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <input type="text" class="layui-input search" name="order_no" placeholder="单号"/>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <input type="text" class="layui-input search" name="n_title" placeholder="报修人/手机号/公司名称"/>
                        </div>
                        <div class="layui-input-inline layui-form">
                            <input type="text"  name="start" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="创建时间-起" />
                        </div>
                        <div class="layui-input-inline layui-form">
                            <input type="text"  name="end" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="创建时间-止" />
                        </div>
                        <div style="clear: both;height: 10px;"></div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button class="layui-btn layui-btn-normal" id="empty" lay-submit="" lay-filter="LAY-search">
                                重置
                            </button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group" >
                        <button  class="btn btn-danger m-l-xs" href="javascript:;" data-toggle="dropdown">
                            <i class="fa fa-wrench"></i> 导出 <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu layui-anim layui-anim-upbit" role="menu">
                            <li><a  href="javascript:;" class="layuiBtn" data-type="excelAll"><i class="fa fa-print"></i> 导出订单</a></li>
<!--                            <li><a  href="javascript:;" class="layuiBtn" data-type="excelAllDetail"><i class="fa fa-print"></i> 导出明细</a></li>-->
                        </ul>
                    </div>
                </div>
                <!--操作框结束-->
            </div>

            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                    <!--状态显示模板-->
                    <script type="text/html" id="order_status">
                        {{# if(d.order_status == 1){ }}
                        待审核
                        {{# } else if(d.order_status == 2){ }}
                        已同意(待寄回)
                        {{# } else if(d.order_status == 3){ }}
                        已拒绝
                        {{# } else if(d.order_status == 4){ }}
                        返厂中(用户已寄回)
                        {{# } else if(d.order_status == 5){ }}
                        检修中
                        {{# } else if(d.order_status == 6){ }}
                        已回寄给用户
                        {{# } else if(d.order_status == 7){ }}
                        已完成
                        {{# } else if(d.order_status == 8){ }}
                        已取消
                        {{# } else{ }}
                        -
                        {{# } }}

                    </script>
                    <script type="text/html" id="order_jiance_status">

                        {{# if(d.order_jiance_status == 1){ }}
                        待审核
                        {{# } else if(d.order_jiance_status == 2){ }}
                        已同意
                        {{# } else if(d.order_jiance_status == 3){ }}
                        已拒绝
                        {{# } else if(d.order_jiance_status == 0){ }}
                        --
                        {{# } else{ }}
                        error
                        {{# } }}

                    </script>
                    <script type="text/html" id="order_company_express_type">

                        {{# if(d.order_company_express_type == 1){ }}
                        包装出货
                        {{# } else if(d.order_company_express_type == 2){ }}
                        入CUS库
                        {{# } else if(d.order_company_express_type == 3){ }}
                        入RMASAC库
                        {{# } else if(d.order_company_express_type == 0){ }}
                        --
                        {{# } else{ }}
                        error
                        {{# } }}

                    </script>

                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <!-- -->
                        <a href="javascript:;" onclick="wk.layer_show('详情','{:url('orderInfo')}?order_id={{d.order_id}}')" class="btn btn-primary btn-xs m-r-xs" title="详情">详情</a>
                        {{# if(d.order_status == 1){ }}
                        <a href="javascript:;" onclick="wk.layer_show('审核', '{:url('orderCheck')}?order_id={{d.order_id}}')" class="btn btn-warning btn-xs m-r-xs" title="审核">审核</a>
                        {{# } }}
                        {{# if(d.order_status == 2){ }}
                        <a href="javascript:;" onclick="wk.layer_show('修改收货地址', '{:url('orderUpdateAddress')}?order_id={{d.order_id}}')" class="btn btn-primary btn-xs m-r-xs" title="修改收货地址">修改收货地址</a>
                        {{# } }}
                        {{# if(d.order_status == 2 || d.order_status == 4 || d.order_status == 5){ }}
                        <a href="javascript:;" onclick="wk.layer_show('订单分配', '{:url('orderAdmin')}?order_id={{d.order_id}}')" class="btn btn-warning btn-xs m-r-xs" title="订单分配">订单分配</a>
                        {{# } }}
                        {{# if(d.order_status == 4){ }}
                        <a href="javascript:;" onclick="wk.layer_show('查看物流','{:url('wuliuInfo')}?express_no={{d.order_user_express_code}}&phone={{d.order_company_phone}}')" class="btn btn-primary btn-xs m-r-xs" title="查看物流">查看物流</a>
                        <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('orderSureGet')}','确认已收到货了吗？')" class="btn btn-primary btn-xs m-r-xs" title="确认收货">确认收货</a>
                        {{# } }}
<!--                        检测审核start-->
                        {{# if(d.order_jiance_status == 1 && d.order_status == 5){ }}
                        <a href="javascript:;" onclick="wk.layer_show('检测是否同意维修', '{:url('orderJianceCheck')}?order_id={{d.order_id}}')" class="btn btn-warning btn-xs m-r-xs" title="检测是否同意维修">检测审核</a>
                        {{# } }}
                        {{# if(d.order_jiance_status == 3 && d.order_status == 5){ }} <!-- 拒绝了也要回寄 -->
                        <a href="javascript:;" onclick="wk.layer_show('回寄', '{:url('orderSend')}?order_id={{d.order_id}}&type=3')" class="btn btn-warning btn-xs m-r-xs" title="回寄">回寄</a>
                        {{# } }}
                        {{# if(d.order_jiance_status == 3 && d.order_status == 6){ }} <!-- 拒绝了也要回寄 -->
                        <a href="javascript:;" onclick="wk.layer_show('修改物流信息', '{:url('orderSend')}?order_id={{d.order_id}}&type=2')" class="btn btn-warning btn-xs m-r-xs" title="修改物流信息">修改物流</a>
                        {{# } }}
<!--                        检测审核end-->
                        {{# if(d.order_jiance_status == 2){ }}
                            <a href="javascript:;" onclick="wk.layer_show('维修方式', '{:url('orderWxfs')}?order_id={{d.order_id}}',1000,500)" class="btn btn-primary btn-xs m-r-xs" title="维修方式">维修方式</a>
                            {{# if(d.order_status == 5){ }} <!-- 检修中 -->
                            <a href="javascript:;" onclick="wk.layer_show('回寄', '{:url('orderSend')}?order_id={{d.order_id}}&type=1')" class="btn btn-warning btn-xs m-r-xs" title="回寄">回寄</a>
                            {{# } }}
                            {{# if(d.order_status == 6){ }} <!-- 已寄回 -->
                                {{# if(d.order_company_express_type == 1){ }}
                                <a href="javascript:;" onclick="wk.layer_show('修改物流信息', '{:url('orderSend')}?order_id={{d.order_id}}&type=2')" class="btn btn-warning btn-xs m-r-xs" title="修改物流信息">修改物流</a>
                                {{# } }}
                            <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('orderDone')}'),'确认订单已完成吗？'" class="btn btn-primary btn-xs m-r-xs" title="确认完成">确认完成</a>
                            {{# } }}
<!--                            {{# if(d.order_status == 8 || d.order_status == 3){ }} &lt;!&ndash; 已取消 &ndash;&gt;-->
<!--                            <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('orderDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>-->
<!--                            {{# } }}-->
                            {{# if(d.order_status >= 5 && d.order_status <= 7){ }} <!-- 检修中 -->
                                {{# if(d.order_status > 5 && d.order_company_express_type == 1){ }} <!-- 检修中 -->
                                <a href="javascript:;" onclick="wk.layer_show('查看物流','{:url('wuliuInfo')}?express_no={{d.order_company_express_code}}&phone={{d.order_user_phone}}&oid={{d.order_id}}')" class="btn btn-warning btn-xs m-r-xs" title="查看物流">查看物流</a>
                                {{# } }}
                            <a href="javascript:;" onclick="wk.layer_show('检修报告', '{:url('orderDevice')}?order_id={{d.order_id}}')" class="btn btn-primary btn-xs m-r-xs" title="检修报告">检修报告</a>
                            {{# } }}
                        {{# } }}
                        <a href="javascript:;" onclick="wk.confirm('{{d.order_id}}','{:url('orderDel')}')" class="btn btn-danger btn-xs m-r-xs" title="删除"><i class="fa fa-trash-o">删除</i></a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<textarea id="allidsForOut" class="hidden"></textarea>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Order/index")}'
            , response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
//            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                // {type: 'checkbox', fixed: 'left',},
                {type: 'numbers', width: 80, title: '序号'}
                , {field: 'order_id', width: '80', title: '订单ID', align: 'center'}
                , {field: 'order_no', width: '', title: '订单号', align: 'center'}
                , {field: 'order_username', width: '', title: '报修人', align: 'center'}
                , {field: 'order_phone', width: '', title: '联系电话', align: 'center'}
                , {field: 'order_number', width: '', title: '商品数量', align: 'center'}
                , {field: 'xuliehao', width: '', title: '序列号', align: 'center'}
                , {field: 'baogaoNum', width: '', title: '报告上传数量', align: 'center'}
                , {field: 'order_company', width: '', title: '单位名称', align: 'center'}
                , {field: 'order_status', width: '', title: '订单状态', align: 'center', toolbar: '#order_status'}
                , {field: 'order_jiance_status', width: '', title: '检测状态', align: 'center', toolbar: '#order_jiance_status'}
                , {field: 'order_jiance_remark', width: '', title: '检测备注', align: 'center'}
                , {field: 'order_wxfs_name', width: '', title: '维修方式', align: 'center'}
                , {field: 'order_company_express_type', width: '', title: '维修方式', align: 'center', toolbar: '#order_company_express_type'}
                , {field: 'order_time', width: '', title: '创建时间', align: 'center'}
                , {fixed: 'right', width: 450, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            , done: function (res, curr, count) {
                $('.img-circle').viewer({
                    url: 'data-original',
                });
            }
        });
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("changeGoodStatus")}',obj);
        });
        //批量操作
        var $ = layui.$, active = {
            excelAll: function(){
                //导出Excel
                wk.excelAll('',$('.layui-input').serialize(),"{:url('excelOutOrder')}");
            },
            excelAllDetail: function(){
                //导出Excel
                wk.excelAll('',$('.layui-input').serialize(),"{:url('excelOutDetail')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                , data = checkStatus.data;
            $.each(data, function (index, item) {
                ids.push(item['order_id'])
            });
            return ids;
        }
    });
</script>
</body>
</html>